package com.wohuijituan.whcsmerchant.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.wohuijituan.whcsmerchant.R;
import com.wohuijituan.whcsmerchant.bean.BankNameListBean;

import java.util.List;

/**
 * 说明：
 * 作者：朱世元
 * 时间： 2016/10/12 16:20
 * 版本：V1.0
 * 修改历史：
 */
public class BankNameAdapter extends MyBaseAdapter<BankNameListBean.DataEntity>{
    //用于图片加载
    private DisplayImageOptions mImageOptions;
    private ImageLoader mImageLoader;
    public BankNameAdapter(Context ctx, List<BankNameListBean.DataEntity> dataList) {
        super(ctx, dataList);
        mImageLoader= ImageLoader.getInstance();
        mImageOptions = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .showImageForEmptyUri(R.drawable.icon_nonghang)
                .showImageOnLoading(R.drawable.icon_nonghang)
                .showImageOnFail(R.drawable.icon_nonghang)
                .build();
    }

    public void setSelPosition(int selPosition) {
        this.selPosition = selPosition;
        notifyDataSetChanged();
    }

    private int selPosition = 0;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if (convertView==null){
            convertView = View.inflate(ctx, R.layout.item_bank_name,null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        }else {
            vh = (ViewHolder) convertView.getTag();
        }
        BankNameListBean.DataEntity data = dataList.get(position);
        vh.tvBankName.setText(data.getB_Name());
        mImageLoader.displayImage(data.getB_Icon(), vh.ivBankIcon, mImageOptions);//给银行设值图标
        if (selPosition==position){
            vh.radioBtnSelect.setChecked(true);
        }else {
            vh.radioBtnSelect.setChecked(false);
        }
        return convertView;
    }
    public class ViewHolder {
        private LinearLayout llSelectBank;
        private ImageView ivBankIcon;
        private TextView tvBankName;
        private RadioButton radioBtnSelect;
        public final View root;
        public ViewHolder(View root) {
            this.root = root;
            llSelectBank = (LinearLayout) root.findViewById(R.id.ll_select_bank);
            ivBankIcon = (ImageView) root.findViewById(R.id.iv_bank_icon);
            tvBankName = (TextView) root.findViewById(R.id.tv_bank_name);
            radioBtnSelect = (RadioButton) root.findViewById(R.id.radio_btn_select);
        }
    }
}
